package com.edusci.backend.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.edusci.backend.pojo.*;
import com.edusci.backend.service.*;
import com.edusci.backend.utils.CourseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/static")
public class PathController {
    @Autowired
    private IInformService informService;
    @Autowired
    private ICourseService courseService;
    @Autowired
    private IActivityService activityService;
    @Autowired
    private ITeacherService teacherService;
    @Autowired
    private ISimulatorService simulatorService;

    @GetMapping("index.html")
    public String index(Model model){
        Page<Course> coursePage = new Page<>();
        coursePage.setCurrent(1).setSize(6);
        Page<Course> coursePage1 = courseService.page(coursePage);
        model.addAttribute("courseList", coursePage.getRecords());

        Page<Teacher> teacherPage = new Page<>();
        teacherPage.setCurrent(1).setSize(3);
        Page<Teacher> teacherPage1 = teacherService.page(teacherPage);
        model.addAttribute("teacherList", teacherPage.getRecords());

        Page<Activity> activityPage = new Page<>();
        activityPage.setCurrent(1).setSize(3);
        Page<Activity> activityPage1 = activityService.page(activityPage);
        model.addAttribute("activityList", activityPage.getRecords());

        return "/user/index";
    }
    @GetMapping("courses.html")
    public String courses(Model model){
        List<Course> courseList = courseService.getAll();
        model.addAttribute("courseList", courseList);
        return "/user/courses";
    }
    @GetMapping("events.html")
    public String events(Model model){
        List<Activity> activityList = activityService.getAll();
        model.addAttribute("activityList", activityList);
        return "/user/events";
    }
    @GetMapping("blog.html")
    public String blog(Model model){
        List<Inform> informList = informService.getAll();
        model.addAttribute("informList", informList);
        return "/user/blog";
    }
    @GetMapping("teacher.html")
    public String teacher(Model model){
        List<Teacher> teacherList = teacherService.getAll();
        model.addAttribute("teacherList", teacherList);
        return "/user/teacher";
    }
    @GetMapping("about.html")
    public String about(){
        return "/user/about";
    }
    @GetMapping("contact.html")
    public String contact(){
        return "/user/contact";
    }
    @GetMapping("notice.html")
    public String notice(){
        return "/user/notice";
    }
    @GetMapping("teacher-single.html")
    public String teacherSingle(){
        return "/user/teacher-single";
    }
    @GetMapping("simulator/{id}")
    public String simulator(@PathVariable int id, Model model){
        CourseUtil courseUtil = new CourseUtil();
        String subject = courseUtil.Corresponding(id);
        LambdaQueryWrapper<Simulator> queryWrapper = Wrappers.<Simulator>lambdaQuery()
                .eq(Simulator::getCourse, id);
        List<Simulator> simulatorList = simulatorService.list(queryWrapper);
        model.addAttribute("subject", subject);
        model.addAttribute("simulatorList", simulatorList);
        System.out.println(simulatorList);
        return "/user/simulator";
    }
}
